

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;

import javax.swing.*;
import javax.swing.border.Border;
public abstract class Tile extends JComponent {
	
	private Image image;
	protected Point p;
	protected static int food;
	protected static int energy;
	protected static int ore;
	protected static int crystite;
	protected Player owner;
	protected Boolean bought = false;
	protected int price;
	private Border bd=BorderFactory.createLineBorder(Color.BLACK, 1);
	
	public Tile(Image image, Point p, int food, int energy, int ore,int crystite ){
		this.image = image;
		this.p = p;
		this.food = food;
		this.energy = energy;
		this.ore = ore;
		this.crystite = crystite; 
		setBorder(bd);
	}
	
	public void draw(Graphics g, int tw, int th){
		g.drawImage(image, p.y * 100, p.x * 100, tw, th, null);
		if(bought){
			bd.paintBorder(this, g, p.y * 100, p.x * 100, tw, th);
		}
	}
	
	public void setOwner(Player p){
		owner=p;
	}
	
	public Boolean isOwned(){
		return bought;
	}
	
	public void beSold(){
		setOwner(null);
		bought = false;
		bd=BorderFactory.createLineBorder(Color.BLACK, 10);
	}
	
	public void beBought(Player player){
		bought = true;
		if (getOwner()==null)
			setOwner(player);
		bd=BorderFactory.createLineBorder(player.getColor(), 10);
	}
	
	public int latestPrice(NewGame.State state){
		if(state == NewGame.State.landGrant)
			price=0;
		if(state == NewGame.State.landBuy)
			price=300;
		return price;
	}
	
	public Player getOwner(){
		return owner;
	}
	
	public int getFood(){
		return food;
	}
	
	public int getEnergy(){
		return energy;
	}
	
	public int getOre(){
		return ore;
	}
	
	public int getCrystite(){
		return crystite;
	}
	
	public void setPrice(){
	}
	
	public int getPrice(){
		return price;
	}
	
}